package com.tqw.shipping.feign;

import com.tqw.entity.Result;
import com.tqw.shipping.dto.ShippingDTO;
import com.tqw.shipping.service.ShippingService;
import com.tqw.vo.ShippingVO;
import ma.glasnost.orika.MapperFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: czm
 * @Date: 2022/04/13/16:11
 * @Description:远程接口调用类
 */
@RestController
public class ShippingFeignController implements ShippingFeignClient{

    @Autowired
    private ShippingService shippingService;

    @Autowired
    private MapperFacade mapperFacade;

    @Override
    public Result<List<ShippingVO>> list(Integer clientId) {
        Result<List<ShippingDTO>> list = shippingService.list(clientId);
        List<ShippingDTO> data = list.getData();
        List<ShippingVO> shippingVOS = mapperFacade.mapAsList(data, ShippingVO.class);
        Result<List<ShippingVO>> result = new Result<>();
        result.setData(shippingVOS);
        return result;
    }

    @Override
    public Result<ShippingVO> getInfoById(Integer id, Integer clientId) {
        ShippingDTO shippingDTO = shippingService.getAddrByClientIdAndId(id, clientId);
        Result result = new Result<>();
        result.setData(shippingDTO);
        return result;
    }

}
